from time import sleep

from selenium.webdriver import ActionChains
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.wait import WebDriverWait

from common.utils import DriverUtil


class BasePage(object):

    def __init__(self, name):

        if name == 'mp':
            self.driver = DriverUtil.get_mp_driver()
        elif name == 'app':
            self.driver = DriverUtil.get_app_driver()
        elif name == 'mis':
            self.driver = DriverUtil.get_mis_driver()
        else:
            raise Exception('平台类型有误')

    def find_ele(self, location, timeout=10, step=0.1):
        return WebDriverWait(self.driver, timeout, step).until(lambda x: x.find_element(*location))


    def find_ele_list(self, location, timeout=10, step=0.1):
        return WebDriverWait(self.driver, timeout, step).until(lambda x: x.find_elements(*location))

    def input_val(self, element, value):
        element.clear()
        element.send_keys(value)

    def click_element(self, element):
        element.click()

    def driver_quit(self):
        DriverUtil.quit_mp_driver()